package cn.tedu.order.contrller;

import cn.tedu.order.service.OrderService;
import cn.tedu.pojo.param.OrderAddParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import result.JsonResult;

@RestController
@RefreshScope //在需要实现动态刷新的类上添加
public class OrderController {
    @Value("${order.name}")
    private String orderName;
    @Autowired
    private OrderService orderService;

    //新增订单
    @PostMapping("/order/add")
    public JsonResult addOrder(OrderAddParam orderAddParam) {
        //调用业务层逻辑
        Boolean result = orderService.addOrder(orderAddParam);
        if (!result) {
            return JsonResult.fail("failed");
        }
        return JsonResult.ok("ok");
    }

    @GetMapping("/get/ordername")
    public JsonResult getOrderName() {
        return JsonResult.ok(orderName);
    }
}
